import { ColumnProps } from '~/library/components/ProTable/interface'
import { getSupplierAPI } from '~/src/api/goods'
import { Inventory } from '~/src/api/interface/goods'
import { getLastQuarterDays } from '~/src/utils/date'
import { formatDate } from '~/src/utils/date-formatter'
import { rejectionStatus, warehouseStatus } from '~/src/utils/serviceDict'

export const columns: ColumnProps<Inventory.ResPurchaseList>[] = [
  // { type: 'selection', width: 60 },
  {
    type: 'index',
    label: '序号',
    search: {
      el: 'date-picker',
      label: '单据日期',
      key: 'timeValue',
      order: 1,
      defaultValue: [formatDate(-getLastQuarterDays(), 'start', 'yyyy-MM-dd'), formatDate(0, 'end', 'yyyy-MM-dd')],
      props: {
        type: 'datetimerange',
        format: 'YYYY-MM-DD',
        valueFormat: 'YYYY-MM-DD',
      },
    },
    width: 60,
  },
  {
    sortable: true,
    prop: 'date',
    label: '收货日期',
    minWidth: 150,
    enum: [
      { label: '收货日期查询', value: 1 },
      { label: '创建时间查询', value: 2 },
    ],

    // enum: timeType, // enum格式化内容，在utils里面有定义好的enum类型数据
    // search 配置是否可以通过上面搜索框搜索到数据
    search: {
      el: 'select',
      label: '日期类型',
      key: 'timeType',
      order: 0,
      defaultValue: 2,
    },
    align: 'center',
  },
  { sortable: true, prop: 'orderNo', label: '单据编号', minWidth: 200, search: { el: 'input' } },
  // {    sortable: true, prop: "orderType", label: "单据类型", minWidth: 120, enum: orderType, align: "left" },
  {
    sortable: true,
    prop: 'supplierName',
    label: '供应商',
    minWidth: 120,
    enum: () => getSupplierAPI({ pageNum: 1, pageSize: 9999 }),
    align: 'center',
    search: { el: 'select', key: 'supplierId' },
    fieldNames: { label: 'name', value: 'id' },
    isFilterEnum: false,
  },
  // {    sortable: true, prop: "", label: "仓库", enum: deliveryStatus, align: "" },
  { sortable: true, prop: 'itemCount', label: '物品（项）', align: 'center', width: 130 },
  { sortable: true, prop: 'amount', label: '金额', align: 'center' },
  {
    sortable: true,
    prop: 'checkFlag',
    label: '单据状态',
    minWidth: 120,
    enum: warehouseStatus,
    align: 'center',
    search: { el: 'select', key: 'checkFlag' },
  },
  {
    sortable: true,
    prop: 'status',
    label: '退货状态',
    minWidth: 120,
    enum: rejectionStatus,
    align: 'center',
    search: { el: 'select', key: 'checkFlag' },
  },
  {
    sortable: true,
    prop: 'sourceNo',
    label: '关联单号',
    minWidth: 140,
    align: 'center',
  },
  {
    sortable: true,
    prop: 'createTime',
    label: '创建时间',
    minWidth: 164,
    align: 'center',
  },
  { sortable: true, prop: 'remark', label: '备注', minWidth: 180, align: 'center', search: { el: 'input' } },
  { prop: 'operation', label: '操作', width: 180, fixed: 'right' },
]
